#include <REGX52.H>
#include "Delay.h"

unsigned char state=0;
unsigned char nowState=0;
unsigned char lastState=0;
unsigned char temp=0;



unsigned char Key_Ret()
{
	temp=0;
	temp=state;
	state=0;
	return temp;
}

unsigned char Key_Check()
{
	unsigned char count=0;
	if(P3_1==0)
	{
		count=1;
		return count;
	}
	else if(P3_0==0)
	{
		count=2;
		return count;
	}
	else if(P3_2==0)
	{
		count=3;
		return count;
	}
	else if(P3_3==0)
	{
		count=4;
		return count;
	}
	return count;
}

void Key_State()
{
	lastState=nowState;
	nowState=Key_Check();
	if(nowState==0&&lastState==1)
	{
		state=1;
	}
	else if(nowState==0&&lastState==2)
	{
		state=2;
	}
	else if(nowState==0&&lastState==3)
	{
		state=3;
	}
	else if(nowState==0&&lastState==4)
	{
		state=4;
	}
}